import { _detail } from '../../common/api/news'
const app = getApp()
const WxParse = require('../../libs/wxParse/wxParse.js')
Page({
  data: {},
  onLoad (options) {
    let code = options.code
    this.data.code = code
    this.getDetail()
  },
  getDetail () {
    app.loading('加载中')
    _detail(this.data.code).then(res => {
      wx.hideLoading()
      console.log(res)
      if (res.data.IsSuccess) {
        wx.setNavigationBarTitle({
          title: res.data.Data.Title
        })
        let content = res.data.Data.Content
        WxParse.wxParse('content', 'html', content, this, 0)
      } else {
        wx.showModal({
          title: '对不起',
          content: res.data.Msg,
          showCancel: false,
          success: r => {
            wx.navigateBack()
          }
        })
      }
    }).catch(err => {
      wx.hideLoading()
      console.log(err)
      wx.showModal({
        title: '对不起',
        content: '请求失败，请稍后再试',
        showCancel: false,
        success: r => {
          wx.navigateBack()
        }
      })
    })
  },
  onReady () {},
  onShow() { },
  onShareAppMessage() {
    return app.shareInfo
  }
})